/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
 * MA  02110-1301, USA.
 *
 * http://www.gnu.org/copyleft/gpl.html
 */
package com.aionemu.gameserver.model.gameobjects.stats.modifiers;

import java.util.ArrayList;

import com.aionemu.gameserver.model.gameobjects.player.Player;
import com.aionemu.gameserver.model.gameobjects.stats.Stat;
import com.aionemu.gameserver.model.gameobjects.stats.StatEnum;
import com.aionemu.gameserver.skillengine.model.IStatEffect;

/**
 * @author Mr. Poke
 *
 */
public final class FunctionModifiers implements IStatEffect
{

	public static void addFuncsToPlayer(Player player)
	{
		ArrayList<StatModifier> modifiers = new ArrayList<StatModifier>();
		modifiers.add(PhysicalAttackModifier.getInstance());
		modifiers.add(MagicalAttackModifier.getInstance());
		modifiers.add(AttackSpeedModifier.getInstance());
		modifiers.add(BoostCastingTimeModifier.getInstance());
		modifiers.add(PvPAttackRatioModifier.getInstance());
		modifiers.add(SpeedModifier.getInstance());
		player.getGameStats().addModifiers(null, modifiers);
	}

	static class PhysicalAttackModifier extends StatModifier
	{
		static final PhysicalAttackModifier instance = new PhysicalAttackModifier();

		static StatModifier getInstance()
		{
			return instance;
		}

		private PhysicalAttackModifier()
		{
			super();
			setStat(StatEnum.PHYSICAL_ATTACK);
			this.setPriority((byte) 0x30);
		}

		@Override
		public void apply(Stat stat)
		{
			float power = stat.getOwner().getGameStats().getPower().getCurrent();
			stat.setBase(stat.getBase()*power/100f);
		}

	}
	
	static class SpeedModifier extends StatModifier
	{
		static final SpeedModifier instance = new SpeedModifier();

		static StatModifier getInstance()
		{
			return instance;
		}

		private SpeedModifier()
		{
			super();
			setStat(StatEnum.SPEED);
			this.setPriority((byte) 0x60);
		}

		@Override
		public void apply(Stat stat)
		{
			if (stat.getCurrent() < 600)
			{
				if (stat.base > 600)
				{
					stat.bonus = 600-stat.base;
				}
			}
		}
	}

	static class MagicalAttackModifier extends StatModifier
	{
		static final MagicalAttackModifier instance = new MagicalAttackModifier();

		static StatModifier getInstance()
		{
			return instance;
		}

		private MagicalAttackModifier()
		{
			super();
			setStat(StatEnum.MAGICAL_ATTACK);
			this.setPriority((byte) 0x30);
		}

		@Override
		public void apply(Stat stat)
		{
			float knowledge = stat.getOwner().getGameStats().getKnowledge().getCurrent();
			stat.setBase(stat.getBase()*knowledge/100f);
		}
	}
	
	static class AttackSpeedModifier extends DuplicateStatModifier
	{
		static final AttackSpeedModifier instance = new AttackSpeedModifier();

		static StatModifier getInstance()
		{
			return instance;
		}

		private AttackSpeedModifier()
		{
			super();
			setStat(StatEnum.ATTACK_SPEED);
			this.setPriority((byte) 0x60);
		}
		
		@Override
		public void apply(Stat stat)
		{
			super.apply(stat);
			if (stat.getCurrent() < stat.base/2)
			{
				stat.bonus = -stat.base/2;
			}
		}
	}
	
	static class BoostCastingTimeModifier extends DuplicateStatModifier
	{
		static final BoostCastingTimeModifier instance = new BoostCastingTimeModifier();

		static StatModifier getInstance()
		{
			return instance;
		}

		private BoostCastingTimeModifier()
		{
			super();
			setStat(StatEnum.BOOST_CASTING_TIME);
			this.setPriority((byte) 0x60);
		}
	}
	
	static class PvPAttackRatioModifier extends DuplicateStatModifier
	{
		static final PvPAttackRatioModifier instance = new PvPAttackRatioModifier();

		static StatModifier getInstance()
		{
			return instance;
		}

		private PvPAttackRatioModifier()
		{
			super();
			setStat(StatEnum.PVP_ATTACK_RATIO);
			this.setPriority((byte) 0x60);
		}
	}
}
